home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / program / misc / bgui12.lha / demos / Colors.c < prev    next >
C/C++ Source or Header  |  1995-05-21  |  8KB  |  146 lines

  1. ;/* Execute me to compile with DICE V3.0
  2. dcc colors.c -mi -ms -mRR -proto -lbgui
  3. quit
  4. */
  5. /*
  6.  *      COLORS.C
  7.  *
  8.  *      (C) Copyright 1995 Jaba Development.
  9.  *      (C) Copyright 1995 Jan van den Baard.
  10.  *          All Rights Reserved.
  11.  */
  12.  
  13. #include "democode.h"
  14.  
  15. /*
  16. **      Object ID's.
  17. **/
  18. #define ID_ALT                  1
  19. #define ID_QUIT                 2
  20.  
  21. VOID StartDemo( void )
  22. {
  23.         struct Window           *window;
  24.         Object                  *WO_Window, *GO_Quit, *GO_B[ 2 ], *GO_Alt;
  25.         ULONG                    signal, rc, tmp = 0, a;
  26.         BOOL                     running = TRUE;
  27.  
  28.         /*
  29.          *      Create the window object.
  30.          */
  31.         WO_Window = WindowObject,
  32.                 WINDOW_Title,           "Colors Demo",
  33.                 WINDOW_AutoAspect,      TRUE,
  34.                 WINDOW_SmartRefresh,    TRUE,
  35.                 WINDOW_RMBTrap,         TRUE,
  36.                 WINDOW_MasterGroup,
  37.                         VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), GROUP_BackFill, SHINE_RASTER,
  38.                                 StartMember,
  39.                                         InfoFixed( NULL, ISEQ_C "This small demo shows you how you can\n"
  40.                                                          "change the background and label colors\n"
  41.                                                          "of an object on the fly.\n\n"
  42.                                                          "As you can see the colors of the below buttons\n"
  43.                                                          "are normal but when the " ISEQ_B "Alternate" ISEQ_N " checkbox\n"
  44.                                                          "is selected the colors are changed.",
  45.                                                          NULL, 7 ),
  46.                                 EndMember,
  47.                                 StartMember,
  48.                                         HGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), FRM_Type, FRTYPE_BUTTON, FRM_Recessed, TRUE,
  49.                                                 StartMember, GO_B[ 0 ] = Button( "Colors", 0 ), EndMember,
  50.                                                 StartMember, GO_B[ 1 ] = Button( "Demo",   0 ), EndMember,
  51.                                         EndObject, FixMinHeight,
  52.                                 EndMember,
  53.                                 StartMember,
  54.                                         HGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), FRM_Type, FRTYPE_BUTTON, FRM_Recessed, TRUE,
  55.                                                 VarSpace( DEFAULT_WEIGHT ),
  56.                                                 StartMember, GO_Alt = KeyCheckBox( "_Alternate", FALSE, ID_ALT ), EndMember,
  57.                                                 VarSpace( DEFAULT_WEIGHT ),
  58.                                         EndObject, FixMinHeight,
  59.                                 EndMember,
  60.                                 StartMember,
  61.                                         HGroupObject,
  62.                                                 VarSpace( DEFAULT_WEIGHT ),
  63.                                                 StartMember, GO_Quit = KeyButton( "_Quit", ID_QUIT ), EndMember,
  64.                                                 VarSpace( DEFAULT_WEIGHT ),
  65.                                         EndObject, FixMinHeight,
  66.                                 EndMember,
  67.                         EndObject,
  68.         EndObject;
  69.  
  70.         /*
  71.         **      Object created OK?
  72.         **/
  73.         if ( WO_Window ) {
  74.                 /*
  75.                 **      Assign the keys to the buttons.
  76.                 **/
  77.                 tmp += GadgetKey( WO_Window, GO_Quit,  "q" );
  78.                 tmp += GadgetKey( WO_Window, GO_Alt,   "a" );
  79.                 /*
  80.                 **      OK?
  81.                 **/
  82.                 if ( tmp == 2 ) {
  83.                         /*
  84.                         **      try to open the window.
  85.                         **/
  86.                         if ( window = WindowOpen( WO_Window )) {
  87.                                 /*
  88.                                 **      Obtain it's wait mask.
  89.                                 **/
  90.                                 GetAttr( WINDOW_SigMask, WO_Window, &signal );
  91.                                 /*
  92.                                 **      Event loop...
  93.                                 **/
  94.                                 do {
  95.                                         Wait( signal );
  96.                                         /*
  97.                                         **      Handle events.
  98.                                         **/
  99.                                         while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  100.                                                 /*
  101.                                                 **      Evaluate return code.
  102.                                                 **/
  103.                                                 switch ( rc ) {
  104.  
  105.                                                         case    WMHI_CLOSEWINDOW:
  106.                                                         case    ID_QUIT:
  107.                                                                 running = FALSE;
  108.                                                                 break;
  109.  
  110.                                                         case    ID_ALT:
  111.                                                                 /*
  112.                                                                  *      When the object is selected we use
  113.                                                                  *      alternate coloring on the objects.
  114.                                                                  *      If not we revert to default coloring.
  115.                                                                  */
  116.                                                                 GetAttr( GA_Selected, GO_Alt, &tmp );
  117.                                                                 /*
  118.                                                                  *      Setup the colors on the buttons.
  119.                                                                  */
  120.                                                                 for ( a = 0; a < 2; a++ )
  121.                                                                         SetGadgetAttrs(( struct Gadget * )GO_B[ a ], window, NULL,
  122.                                                                                 FRM_BackDriPen,                 tmp ? TEXTPEN  : (ULONG)~0,
  123.                                                                                 FRM_SelectedBackDriPen,         tmp ? SHINEPEN : (ULONG)~0,
  124.                                                                                 LAB_DriPen,                     tmp ? SHINEPEN : (ULONG)~0,
  125.                                                                                 LAB_SelectedDriPen,             tmp ? TEXTPEN  : (ULONG)~0,
  126.                                                                                 TAG_END );
  127.                                                                 break;
  128.                                                 }
  129.                                         }
  130.                                 } while ( running );
  131.                         } else
  132.                                 Tell( "Could not open the window\n" );
  133.                 } else
  134.                         Tell( "Could not assign gadget keys\n" );
  135.                 /*
  136.                 **      Disposing of the window object will
  137.                 **      also close the window if it is
  138.                 **      already opened and it will dispose of
  139.                 **      all objects attached to it.
  140.                 **/
  141.                 DisposeObject( WO_Window );
  142.         } else
  143.                 Tell( "Could not create the window object\n" );
  144. }
  145.  
  146.